package com.lz.ad.canal;

import com.lz.ad.canal.common.Config;
import com.lz.zookeeper.ZooKeeperClient;
import com.lz.zookeeper.ZooKeeperUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created by Li Tiefei on 2018/12/24.
 */
@Slf4j
@Component
public class Init {

    //获取zk实例
    private final static ZooKeeperClient ZOOKEEPERCLIENT = ZooKeeperClient.getInstance(Config.ZK_SERVER_PATH, Config.ZK_CONFIG_PATH, Config.class);

    @PostConstruct
    public static void init() throws Exception{
        log.debug("======================" + Init.class +" init()========================");
        ZooKeeperUtil.startupZk(ZOOKEEPERCLIENT, "");
    }

    @PreDestroy
    public static void destroy() throws Exception {
        log.debug("======================" + Init.class +" destroy()========================");
        ZooKeeperUtil.shutdownZk(ZOOKEEPERCLIENT);
    }
}
